package com.yuelao.yuelao_backend.controller;

import com.yuelao.yuelao_backend.common.ApiResponse;
import com.yuelao.yuelao_backend.service.Web3Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/web3")
@Slf4j
public class Web3Controller {

    @Resource
    private Web3Service web3Service;

    /**
     * 获取支持的钱包列表
     * GET /web3/wallets
     * @return 支持的钱包类型列表
     */
    @GetMapping("/wallets")
    public ApiResponse<List<String>> getSupportedWallets() {
        List<String> wallets = web3Service.getSupportedWallets();
        return ApiResponse.ok(wallets);
    }

    /**
     * 连接Web3钱包
     * POST /web3/connect
     * @param walletType 钱包类型
     * @return 连接是否成功
     */
    @PostMapping("/connect")
    public ApiResponse<Boolean> connectWallet(@RequestParam String walletType) {
        boolean result = web3Service.connectWallet(walletType);
        return ApiResponse.ok(result);
    }

    /**
     * 获取代币兑换汇率
     * GET /web3/exchange-rate
     * @return 兑换汇率
     */
    @GetMapping("/exchange-rate")
    public ApiResponse<Double> getExchangeRate() {
        Double rate = web3Service.getExchangeRate();
        return ApiResponse.ok(rate);
    }
}